package service.impl;

import dao.UserDao;
import service.UserService;
import vo.Users;

import java.util.List;

public class UserServiceImpl implements UserService {

    private final UserDao userDao = UserDao.getInstance();

    @Override
    public Users userLogin(Users users) {
        //进行业务逻辑处理
        return userDao.userLogin(users);
    }

    @Override
    public List<Users> queryUserList(String userName) {
        if(userName!=null && !userName.isEmpty()){
            userName = "%"+userName+"%";
        }
        return userDao.queryUserList(userName);
    }

    @Override
    public int insertUser(Users users) {
        int rows= 0 ;
        //新增id是没有值的，更新id是有值的
        if(users.getId()==null){
            rows = userDao.insertUser(users);
        }else{
            rows = userDao.updateUser(users);
        }
        return rows;
    }

    @Override
    public int deleteUser(int id) {
        return userDao.deleteUser(id);
    }

    @Override
    public Users queryUserById(int id) {
        return userDao.queryUserById(id);
    }


}
